/**
 * Controller.java
 * 
 * @authors: Connor Gordon, Difan Zhao, Kathleen Lan, Patrick Royal
 */

package control;

import java.util.List;
import model.Element;
import model.ElementManager;
import view.View;


/**
 * Calls the model to read in data from the file and put it
 * into a readable form, and then pass it through the controller
 * to the view.
 * 
 * @author Group 8
 * 
 */
public abstract class Controller {

    protected View myView;
    private ElementManager myElementManager;
    private List<Element> myElements;

    /**
     * Constructor for Controller.
     */
    public Controller () {
        myView = new View("My Data Visualizer", this);
        myElementManager = new ElementManager();
    }

    /**
     * Prompts user for file, url, and extension.
     */
    public void run () {
        myView.introMessage();
        String filename = promptForName();
        String url = promptForURL();
        String ext = promptForExt();
        myElements = processInput(myElementManager, filename, url, ext);
        myView.setVisible(true);
        myView.createVisualization(myElements);
    }

    /**
     * Calls the promptName method in the View and returns its return value.
     */
    protected String promptForName () {
    	return myView.promptName();
    }
    
    /**
     * Calls the promptURL method in the View and returns its return value.
     */
    protected String promptForURL () {
        return myView.promptURL();
    }
    
    /**
     * Calls the promptExt method in the View and returns its return value.
     */
    protected String promptForExt () {
    	return myView.promptExt();
    }

    /**
     * Returns a list of values for a data set.
     * 
     * @param elementName name of the data set
     */
    public abstract List<Integer> getElementData (String elementName);

    protected abstract List<Element> processInput (ElementManager em,
            String filename, String url, String ext);

    /**
     * Provides read-only access to view.
     */
    public View getView() {
        return myView;
    }

    /**
     * Provides read-only access to manager.
     */
    public ElementManager getManager() {
        return myElementManager;
    }

    /**
     * Provides read-only access to elements.
     */
    public List<Element> getElements() {
        return myElements;
    }
}
